<template>
	<div>
		<view class="status_bar">
			<!-- 这里是状态栏 -->
		</view>
		<view class="head">
			<image class="back_image" src="../../static/icons/goback.png" @click="back"></image>
			<text class="head_text">我的地址</text>
			<image class="tianjia_image" src="../../static/icons/jiahao.png" @click="tianjia"></image>
		</view>
		
		<uni-swipe-action>
			<block :key="index" v-for="(presentAddress,index) in presentAddress" v-if="1">
				<uni-swipe-action-item :options="options" :autoClose="true" @click="onClick(presentAddress.id)" @change="change">
					<div @click="toEdit_address(presentAddress.id)">
					<div class='city'>
						{{presentAddress.linkname}}
					</div>
					<div class='weather1'>
						{{presentAddress.address}}&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
						{{presentAddress.phone}}
					</div>
					</div>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
	</div>
</template>
<script>
	import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue'
	import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue'
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	export default {
		components: {
			uniSwipeAction,
			uniSwipeActionItem,
			uniNavBar
		},
		data() {
			return {
				presentAddress: [],
				right: 'right',
				address: '',
				lenth: 0,
				// address: [1, 1],
				location: '',

				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
			}
		},
		methods: {
			back: function(e) {
				console.log(e);
				uni.navigateBack({
					delta: 1
				})
			},
			tianjia: function(e) {
				uni.navigateTo({
					url: "add_address"
				})
			},
			toEdit_address(id){
				uni.navigateTo({
					url:'edit_address?id='+id
				})
			},
			onClick(id) {
				var that = this
				this.$uni.request({
					url: '/address/deleteAddress/' + id,
					header: {
						cookie: this.$store.state.cookie
					},
				}).then(res => {
					this.text = 'request success';
					uni.redirectTo({
						url: '../user/user_address'
					})
				})
				// console.log('当前点击的是第'+e.index+'个按钮，点击内容是'+e.target.id)
				console.log(id)
			},
			change(open) {
				console.log('当前开启状态：' + open)
			},
			// getNowData: function() {
			// 	var that = this
			// 	for (let index in this.address) {
			// 		console.log(this.address[index].id)
			// 		var id = this.address[index].id
			// 		console.log(id)

			// 		uni.request({
			// 			url: "https://api.seniverse.com/v3/weather/now.json?key=" + that.xinZhiKey + "&location=" + this.city[index].city_id +
			// 				"&language=zh-Hans&unit=c",
			// 			method: "GET",
			// 			success: function(data) {
			// 				that.nowData = data.data.results[0]
			// 				that.presentCity.push(that.nowData)
			// 				console.log(that.presentCity)
			// 				// console.log(nowData.location.name)
			// 			}
			// 		})
			// 	}
			// },
			// getAddressById: function(e) {
			// 	return new Promise((reslove, reject) => {
			// 		this.$uni.request({
			// 			url: '/address/getAddressById',
			// 		}).then(data => {
			// 			that.nowData = data.data.results[0]
			// 			that.presentAddress.push(that.nowData)
			// 			reslove(data.data)
			// 		})
			// 	})
			// },
			// onShow: function() {
			// 	uni.getLocation({
			// 		type: 'wgs84',
			// 		success: async (res) => {
			// 			console.log(res)
			// 			// this.location = res.latitude + ":" + res.longitude
			// 			this.address = await this.getAddressById()
			// 			console.log(this.address)
			// 			// this.getNowData()
			// 		}
			// 	})
			// },
			onShow() {
			    var that = this;
				// this.$uni.request({
				// 	url: '/address/getAddressById',
				// }).then(data => {
				// 	that.address = data.data.results[0]
				// 	that.presentAddress.push(that.address)
				// });
				uni.request({
					url: 'http://localhost:10998/address/getAddressById',
					method: "GET",
					success: function(data) {
						// that.lenth = data.data.address.length
						// console.log(that.lenth)
						for (var i=0;i<data.data.address.length;i++){
						that.address = data.data.address[i]
						that.presentAddress.push(that.address)
						console.log(that.presentAddress)
						}
						// console.log(nowData.location.name)
					}
				});
			},
		}
	}
</script>
<style scoped>
	.city {
		width: 100%;
		height: 80px;
		padding: 10px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-direction: row;
		flex-wrap: wrap;
	}

	.weather1 {
		width: 100px;
		align-self: center;

	}

	.weather {
		margin-left: 100rpx;
		display: flex;
		align-items: center;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
		background-color: #324178;
	}

	.head {
		background-color: #324178;
		height: 100rpx;
		display: flex;
		align-items: center;
		-moz-box-shadow: 2px 5px 10px #324178;
		-webkit-box-shadow: 2px 5px 10px #324178;
		box-shadow: 2px 5px 10px #324178;
	}

	.head_text {
		font-size: 36rpx;
		color: #FFFFFF;
		margin: 0 auto;
	}

	.back_image {
		width: 64rpx;
		height: 64rpx;
		margin-left: 20rpx;
		position: absolute;
	}

	.tianjia_image {
		width: 64rpx;
		height: 64rpx;
		margin-left: 650rpx;
		position: absolute;
	}
</style>
